Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dptest): Wrong dptest results except for energy head #4280

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

Chengqian-Zhang
Copy link
Collaborator

@Chengqian-Zhang Chengqian-Zhang commented Oct 30, 2024

Solve issue #4249

In /deepmd/entrypoints/test.py line 127 tmap = dp.get_type_map() if isinstance(dp, DeepPot) else None. If we use DeepProperty or DeepPolar or DeepDOS..... tmap is None. So type_map is not modified again according to type_map in input.json. So atype is wrong in the model forward process. The model prediction value is wrong.

According to @njzjz , It seems that in the r2 branch, get_type_map() is only available in DeepPot. After we refactor DeepEval in v3, this should not be a problem anymore.

I also change the order of type_map in UT to ensure that when type_map of input.json doesn't match the type_map of data, the result of the dptest is still correct.

Summary by CodeRabbit

  • New Features

    • Introduced warning logs for unsupported DeepGlobalPolar model usage, recommending the DeepPolar model instead.
  • Bug Fixes

    • Simplified logic for obtaining the type map, ensuring consistent retrieval from the updated source.
    • Adjusted model configuration in tests to influence type interpretation.
  • Documentation

    • Improved clarity of comments and logging statements for better understanding.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request focus on the test function within the deepmd/entrypoints/test.py file, specifically regarding the handling of the DeepGlobalPolar model. A warning log is introduced to inform users that this model is unsupported, recommending the DeepPolar model instead. The retrieval of the type map (tmap) has been simplified by removing unnecessary conditional checks. While the error handling for invalid systems remains unchanged, minor adjustments to comments and logging statements enhance clarity without affecting functionality.

Changes

File Path Change Summary
deepmd/entrypoints/test.py - Added warning log for unsupported DeepGlobalPolar model.
- Simplified tmap retrieval logic.
- Minor adjustments to comments and logging for clarity.
- Error handling for invalid systems remains unchanged.
source/tests/pt/test_dp_test.py - Modified setUp method to reorder type_map elements.
- Changed atomic parameter to True in test_dp_test_1_frame method.

Suggested reviewers

  • njzjz
  • iProzd

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 63b347d and fa886f7.

📒 Files selected for processing (1)
  • source/tests/pt/test_dp_test.py (1 hunks)
🔇 Additional comments (2)
source/tests/pt/test_dp_test.py (2)

155-157: LGTM! Good test case for type_map handling.

This change introduces a deliberate permutation of the type_map to validate that dptest correctly handles type mappings from input.json, which directly addresses the issue #4249 where type_map wasn't being properly updated for non-DeepPot models.


Line range hint 182-194: LGTM! Verify atomic property predictions.

Setting atomic=True is appropriate for testing DeepProperty models. The test correctly validates the property predictions against the model's output.

Let's verify that this test case covers the type_map handling issue:

✅ Verification successful

Property tests correctly handle atomic parameter variations

The verification shows that:

  • The test suite already has comprehensive coverage for both atomic=True and atomic=False cases
  • In test_property_fitting.py, both atomic and non-atomic evaluations are tested
  • The current change in test_dp_test.py complements existing tests by adding atomic property testing while maintaining the non-atomic test case

The atomic parameter handling is well-tested across the codebase, and this change appropriately extends the test coverage.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there are other test cases that might need similar atomic=True setting

# Look for other property test cases that might need updating
rg -l "class.*Test.*Property" source/tests/

Length of output: 342


Script:

#!/bin/bash
# Check for similar property test patterns and atomic parameter usage
rg -A 5 -B 5 "test.*property" source/tests/pt/test_dp_test.py source/tests/pt/model/test_property_fitting.py source/tests/consistent/fitting/test_property.py

# Also check for atomic parameter usage in these files
rg -A 2 -B 2 "atomic\s*=\s*(True|False)" source/tests/pt/test_dp_test.py source/tests/pt/model/test_property_fitting.py source/tests/consistent/fitting/test_property.py

Length of output: 4113


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
deepmd/entrypoints/test.py (1)

Line range hint 182-187: Consider raising an error for unsupported models.

While the warning message is helpful, allowing an unsupported model to continue processing might lead to incorrect results without the user noticing.

Consider either:

  1. Raising an error to prevent using unsupported models:
         elif isinstance(dp, DeepGlobalPolar):  # should not appear in this new version
-            log.warning(
-                "Global polar model is not currently supported. Please directly use the polar mode and change loss parameters."
-            )
-            err = test_polar(
-                dp, data, numb_test, detail_file, atomic=False
-            )  # YWolfeee: downward compatibility
+            raise ValueError(
+                "Global polar model is not supported in this version. Please use the DeepPolar model instead and adjust loss parameters accordingly."
+            )
  1. Or add a stronger warning about potential incorrect results:
         elif isinstance(dp, DeepGlobalPolar):  # should not appear in this new version
             log.warning(
-                "Global polar model is not currently supported. Please directly use the polar mode and change loss parameters."
+                "Global polar model is not currently supported and may produce incorrect results. Please use the DeepPolar model instead and adjust loss parameters accordingly."
             )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d165fee and 63b347d.

📒 Files selected for processing (1)
  • deepmd/entrypoints/test.py (1 hunks)

deepmd/entrypoints/test.py Show resolved Hide resolved
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.29%. Comparing base (d165fee) to head (fa886f7).
Report is 6 commits behind head on devel.

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #4280   +/-   ##
=======================================
  Coverage   84.29%   84.29%           
=======================================
  Files         553      553           
  Lines       51820    51820           
  Branches     3052     3052           
=======================================
+ Hits        43683    43684    +1     
+ Misses       7177     7175    -2     
- Partials      960      961    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Chengqian-Zhang
Copy link
Collaborator Author

Maybe who can help me rerun the failed UT? I do not have the permission. I don't think it is a code problem.

@Chengqian-Zhang
Copy link
Collaborator Author

image

@njzjz njzjz linked an issue Oct 30, 2024 that may be closed by this pull request
@njzjz
Copy link
Member

njzjz commented Oct 30, 2024

Maybe who can help me rerun the failed UT? I do not have the permission. I don't think it is a code problem.

Fixed.

@iProzd iProzd added this pull request to the merge queue Oct 31, 2024
@iProzd iProzd removed this pull request from the merge queue due to a manual request Oct 31, 2024
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Oct 31, 2024
Merged via the queue into deepmodeling:devel with commit cdad312 Oct 31, 2024
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Wrong dptest results except for energy head
4 participants